import java.util.Stack;

/**
 * https://leetcode.cn/problems/valid-parentheses/
 *
 * @author zyj
 * @date 2022年05月20日 9:52
 */
public class _20_有效的括号 {
    public static boolean isValid(String s) {
        char[] arrays = s.toCharArray();
        Stack<Character> stack = new Stack<>();
        for (char c:arrays) {
            if (c == '{'){
                stack.push('}');
            }else if (c == '['){
                stack.push(']');
            }else if (c == '('){
                stack.push(')');
            }else if (stack.isEmpty() || c != stack.pop()){
                return false;
            }
        }

        return stack.empty();
    }

    public static void main(String[] args) {
        System.out.println(isValid("{{{}}}{([]"));
    }
}
